package org.demo.controller;

import org.demo.common.Result;
import org.demo.entity.Community;
import org.demo.entity.Message;
import org.demo.entity.MessageDto;
import org.demo.service.ICommunityService;
import org.demo.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//留言表
@RestController
@RequestMapping("/message")
public class MessageConteoller {
    @Autowired
    private IMessageService messageService;

    @PostMapping("/add")
    public Result add(@RequestBody Message message){
        if (message.getContent()==null || message.getContent().equals("")){
            return Result.error("请输入评论");
        }
        messageService.add(message);
        return Result.success();
    }
    @PostMapping("/list")
    public Result<List<MessageDto>> list(@RequestBody (required = false) Message message){
        List<MessageDto> list= messageService.list(message);
        return Result.success(list);
    }
    @PutMapping("/update")
    public Result update(@RequestBody Message message){
        if (message.getContent()==null || message.getContent().equals("")){
            return Result.error("请输入评论");
        }
        messageService.update(message);
        return Result.success();
    }
    // 后端修改为路径参数接收方式
    // 后端修改为路径参数接收
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable String id) {
        messageService.delete(id);
        return Result.success();
    }
}
